package iosu.java.games.razer.server;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Enumeration;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

public class ServerPanel extends JPanel{
private RazerServer s;
private int ini_x=20;
private int ini_y=20;
int xi = 1;

	    public ServerPanel(RazerServer s) {
	        setBorder(BorderFactory.createLineBorder(Color.black));
	        this.s = s;
	    }

	    public Dimension getPreferredSize() {
	        return new Dimension(640,480);
	    }

	    @Override public void paintComponent(Graphics g) {
	        super.paintComponent(g);      
	        g.drawString(String.valueOf(++xi), 100, 20);
	        g.drawString("partidas: "+this.s.partidas.size(),10,20);
	        // partidas Integer, Game
	        Enumeration<Game> enumeration = this.s.partidas.elements();
	        System.out.println(this.s.partidas.size());
	        while (enumeration.hasMoreElements()) {
	        	dibujaPartida(enumeration.nextElement(),g,xi++);
	        }
	        
	    }  
	    
	    private void dibujaPartida(Game game, Graphics g,int i){
	    	String res = "e";
	    	try{
	    	res = "partida "+game.getGameid() +":"+
	    			game.getCar1().getClientid()+","+
	    			game.getCar2()==null?"x":game.getCar2().getClientid()+","+
	    			game.getCar3()==null?"x":game.getCar3().getClientid()+","+
	    			game.getCar4()==null?"x":game.getCar4().getClientid()+" - "+
	    			game.getStartingtime();
	    	}catch(Exception e){
	    		
	    	}
	    	System.out.println("dibujando "+res);
   			g.drawString(res, ini_x, ini_y*i);
	    	
	    }


}
